{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "训练数据量：120，测试数据量：30\n",
      "准确率：0.97\n"
     ]
    }
   ],
   "source": [
    "from sklearn.ensemble import AdaBoostClassifier\n",
    "from sklearn import datasets\n",
    "from sklearn.model_selection import train_test_split\n",
    "from sklearn import metrics\n",
    "\n",
    "iris = datasets.load_iris()\n",
    "X = iris.data\n",
    "y = iris.target\n",
    "\n",
    "X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)\n",
    "\n",
    "print(f\"训练数据量：{len(X_train)}，测试数据量：{len(X_test)}\")\n",
    "\n",
    "# 定义模型\n",
    "model = AdaBoostClassifier(n_estimators=50,learning_rate=1.5)\n",
    "# 训练\n",
    "model.fit(X_train, y_train) \n",
    "# 预测\n",
    "y_pred = model.predict(X_test) \n",
    "acc = metrics.accuracy_score(y_test, y_pred) # 准确率\n",
    "print(f\"准确率：{acc:.2}\")\n"
   ]
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "47dfafb046f9703cd15ca753999a7e7c95274099825c7bcc45b473d6496cd1b0"
  },
  "kernelspec": {
   "display_name": "Python 3.7.11 64-bit ('py37': conda)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
